local RSNG = RSNG
local AceOO = AceLibrary("AceOO-2.0")
local L = AceLibrary("Ace-Locale-2.2"):new("RSNG")
local C = RSNG.Classes

local Filter = AceOO.Class(C.IFilter)

function Filter.prototype:init()
	Filter.super.prototype.init(self)
	self.groups = {}
end

function Filter.prototype:Filter(unit, name, class, group)
	return self.groups[group]
end

function Filter.prototype:Serialize(type, data)
	local g = self.groups
	if type == "save" then
		for i = 1, 8 do
			data[i] = g[i]
		end
	elseif type == "load" then
		for i = 1, 8 do
			g[i] = data[i]
		end
	end
end

function Filter.prototype:GetOptionTable()
	local t = self.options
	if not t then
		t = {}
		for i = 1, 8 do
			t["group"..i] = {
				type = "toggle",
				name = L["Group %d"]:format(i),
				desc = L["Filter group %d."]:format(i),
				get = function () return self.groups[i] end,
				set = function (value) self.groups[i] = value and true or false end,
			}
		end
		self.options = t
	end
	return t
end

RSNG:RegisterFilter(L["Group Filter"], Filter)
